﻿using System.Collections.Generic;
using System.Linq;
using Contracts.Entities;

namespace Definition.WebImport
{
    public class TmdbGetCover
    {
        public byte[] Find(IEnumerable<TmdbMovieImage> images)
        {
            var results = new byte[]{};

            if (images != null)
            { 
                var movieImage = images.FirstOrDefault((image) => image.Size == "cover" && image.Url.Contains("jpg")); 
                
                if (movieImage  != null)
                    results = WebClientRequest.GetBytes(movieImage.Url);   
            }

            return results;
        }
    }
}
